<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class Login extends Controller 
{
    
    public function login(){
        return $this->fetch();
    }
    
    public function dulogin(){
        $username = input('post.username');
        $password = input('post.password');
        if(!$username || !$password){json_exit(1,'缺少参数');}
        
        $user = Db::name('user')->where(['username'=>$username])->find();
        if(!$user){json_exit(1,'账号或密码错误');}
        $_password = md5(md5($password));
        if($_password !== $user['password']){json_exit(1,'账号或密码错误');}
        
        session('user',$user);
        json_exit(0,'登录成功');
    }
    
    public function outlogin(){
        
        Session::delete('user');
        json_exit(0,'退出成功');
        
    }
}